from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-06-12 14:02:14.087698
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 12, Jun, 2022
Time: 14:02:19
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.5304
Nobs: 685.000 HQIC: -49.8952
Log likelihood: 8510.23 FPE: 1.70130e-22
AIC: -50.1255 Det(Omega_mle): 1.49325e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.307824 0.058842 5.231 0.000
L1.Burgenland 0.104964 0.038251 2.744 0.006
L1.Kärnten -0.109202 0.020179 -5.412 0.000
L1.Niederösterreich 0.201884 0.079824 2.529 0.011
L1.Oberösterreich 0.117845 0.078514 1.501 0.133
L1.Salzburg 0.255700 0.040813 6.265 0.000
L1.Steiermark 0.044836 0.053407 0.840 0.401
L1.Tirol 0.107413 0.043160 2.489 0.013
L1.Vorarlberg -0.057247 0.037680 -1.519 0.129
L1.Wien 0.030713 0.069550 0.442 0.659
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.044860 0.124411 0.361 0.718
L1.Burgenland -0.032898 0.080875 -0.407 0.684
L1.Kärnten 0.040021 0.042664 0.938 0.348
L1.Niederösterreich -0.181539 0.168772 -1.076 0.282
L1.Oberösterreich 0.436799 0.166002 2.631 0.009
L1.Salzburg 0.285174 0.086292 3.305 0.001
L1.Steiermark 0.107450 0.112919 0.952 0.341
L1.Tirol 0.317147 0.091254 3.475 0.001
L1.Vorarlberg 0.027058 0.079667 0.340 0.734
L1.Wien -0.036618 0.147049 -0.249 0.803
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.190144 0.030279 6.280 0.000
L1.Burgenland 0.089479 0.019683 4.546 0.000
L1.Kärnten -0.007589 0.010384 -0.731 0.465
L1.Niederösterreich 0.258686 0.041076 6.298 0.000
L1.Oberösterreich 0.140483 0.040402 3.477 0.001
L1.Salzburg 0.045214 0.021002 2.153 0.031
L1.Steiermark 0.023672 0.027482 0.861 0.389
L1.Tirol 0.090185 0.022209 4.061 0.000
L1.Vorarlberg 0.057836 0.019389 2.983 0.003
L1.Wien 0.112961 0.035789 3.156 0.002
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.111139 0.030512 3.642 0.000
L1.Burgenland 0.044433 0.019835 2.240 0.025
L1.Kärnten -0.014045 0.010464 -1.342 0.179
L1.Niederösterreich 0.186482 0.041392 4.505 0.000
L1.Oberösterreich 0.314540 0.040712 7.726 0.000
L1.Salzburg 0.103507 0.021163 4.891 0.000
L1.Steiermark 0.107666 0.027694 3.888 0.000
L1.Tirol 0.101952 0.022380 4.555 0.000
L1.Vorarlberg 0.068322 0.019538 3.497 0.000
L1.Wien -0.024852 0.036064 -0.689 0.491
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.123836 0.056109 2.207 0.027
L1.Burgenland -0.046940 0.036474 -1.287 0.198
L1.Kärnten -0.045937 0.019241 -2.387 0.017
L1.Niederösterreich 0.147347 0.076115 1.936 0.053
L1.Oberösterreich 0.148301 0.074866 1.981 0.048
L1.Salzburg 0.282360 0.038917 7.255 0.000
L1.Steiermark 0.053043 0.050926 1.042 0.298
L1.Tirol 0.168502 0.041155 4.094 0.000
L1.Vorarlberg 0.097849 0.035929 2.723 0.006
L1.Wien 0.074062 0.066318 1.117 0.264
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.061980 0.044348 1.398 0.162
L1.Burgenland 0.032208 0.028829 1.117 0.264
L1.Kärnten 0.051390 0.015208 3.379 0.001
L1.Niederösterreich 0.207971 0.060161 3.457 0.001
L1.Oberösterreich 0.302736 0.059174 5.116 0.000
L1.Salzburg 0.043377 0.030760 1.410 0.158
L1.Steiermark 0.007454 0.040251 0.185 0.853
L1.Tirol 0.137042 0.032529 4.213 0.000
L1.Vorarlberg 0.074330 0.028398 2.617 0.009
L1.Wien 0.082050 0.052418 1.565 0.118
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.170469 0.053191 3.205 0.001
L1.Burgenland 0.000746 0.034577 0.022 0.983
L1.Kärnten -0.064208 0.018241 -3.520 0.000
L1.Niederösterreich -0.089964 0.072157 -1.247 0.212
L1.Oberösterreich 0.200830 0.070973 2.830 0.005
L1.Salzburg 0.055073 0.036894 1.493 0.136
L1.Steiermark 0.241183 0.048278 4.996 0.000
L1.Tirol 0.499382 0.039015 12.800 0.000
L1.Vorarlberg 0.053081 0.034061 1.558 0.119
L1.Wien -0.064178 0.062870 -1.021 0.307
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.155054 0.059940 2.587 0.010
L1.Burgenland -0.007156 0.038965 -0.184 0.854
L1.Kärnten 0.062095 0.020555 3.021 0.003
L1.Niederösterreich 0.193150 0.081313 2.375 0.018
L1.Oberösterreich -0.071757 0.079979 -0.897 0.370
L1.Salzburg 0.208361 0.041575 5.012 0.000
L1.Steiermark 0.135687 0.054404 2.494 0.013
L1.Tirol 0.069360 0.043966 1.578 0.115
L1.Vorarlberg 0.133635 0.038383 3.482 0.000
L1.Wien 0.123972 0.070847 1.750 0.080
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.375121 0.035014 10.713 0.000
L1.Burgenland 0.001598 0.022762 0.070 0.944
L1.Kärnten -0.022467 0.012008 -1.871 0.061
L1.Niederösterreich 0.217134 0.047499 4.571 0.000
L1.Oberösterreich 0.210444 0.046720 4.504 0.000
L1.Salzburg 0.042366 0.024286 1.744 0.081
L1.Steiermark -0.017912 0.031780 -0.564 0.573
L1.Tirol 0.102596 0.025683 3.995 0.000
L1.Vorarlberg 0.064921 0.022422 2.895 0.004
L1.Wien 0.028106 0.041386 0.679 0.497
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.037522 0.125880 0.184346 0.148273 0.107600 0.090072 0.047184 0.211840
Kärnten 0.037522 1.000000 -0.016670 0.132962 0.053786 0.092496 0.438995 -0.057077 0.094573
Niederösterreich 0.125880 -0.016670 1.000000 0.329676 0.138220 0.290028 0.081586 0.170549 0.311449
Oberösterreich 0.184346 0.132962 0.329676 1.000000 0.223601 0.316184 0.167810 0.153390 0.260465
Salzburg 0.148273 0.053786 0.138220 0.223601 1.000000 0.134651 0.105462 0.126143 0.134261
Steiermark 0.107600 0.092496 0.290028 0.316184 0.134651 1.000000 0.140791 0.119479 0.064374
Tirol 0.090072 0.438995 0.081586 0.167810 0.105462 0.140791 1.000000 0.092966 0.143961
Vorarlberg 0.047184 -0.057077 0.170549 0.153390 0.126143 0.119479 0.092966 1.000000 0.007596
Wien 0.211840 0.094573 0.311449 0.260465 0.134261 0.064374 0.143961 0.007596 1.000000